home *** CD-ROM | disk | FTP | other *** search
- /*
- * AutoMouse.c
- *
- * Robert Dierkes, April 26, 1993
- *
- * Change History:
- *
- * 4/93 ??? New
- * 4/96 bob Updated #includes to support changed GX Library names.
- * Changed fixed to Fixed.
- * Changed fract to Fract.
- * Changed boolean to Boolean.
- * Added the copyright info.
- *
- *
- * © Apple Computer, Inc. 1990 - 1996 All rights reserved
- *
- */
-
- /*------------------*/
- /* Include Files */
- /*------------------*/
- #include <GXMath.h>
- #include <GXGraphics.h>
- #include <GXEnvironment.h>
-
- #include "AutoMouse.h"
-
-
- /*----------------------*/
- /* Global Declarations */
- /*----------------------*/
- Boolean gMoveMouse,
- gFirstTime;
- Fixed gDegrees;
- long gScale;
- Point gPosition,
- gLocalCenter,
- gCenter;
-
-
- /*------------------------------*/
- /* External Declarations */
- /*------------------------------*/
-
-
- #define MTemp 0x0828
- #define RawMouse 0x082C
- #define CrsrCouple 0x08CF
- #define CrsrNew 0x08CE
-
- #define MTempL (*((long *) MTemp))
- #define RawMouseL (*((long *) RawMouse))
-
- #define CrsrCoupleB (*((char *) CrsrCouple))
- #define CrsrNewB (*((char *) CrsrNew))
-
- #define SetMousePosition(p) {MTempL = RawMouseL = *((long *) p); CrsrNewB = CrsrCoupleB;}
-
-
- void InitializeAutoMouse (gxShape boundsShape)
- {
- gxRectangle bounds;
-
- gMoveMouse = false;
- gFirstTime = true;
- gDegrees = 0;
-
- GXGetShapeBounds (boundsShape, 0, &bounds);
-
- /* Assumes the bounds are square */
- gScale = FixedToInt (bounds.right - bounds.left) / 2;
-
- /* Get center of boundsShape */
- gLocalCenter.h = gScale + FixedToInt (bounds.left);
- gLocalCenter.v = gScale + FixedToInt (bounds.top);
-
- gScale -= 16;
- }
-
-
- Boolean ToggleAutoMouse (void)
- {
- /* Is gPosition outside bounds of boxes?
- Move mouse inside bounds
- */
-
- if (gMoveMouse = ! gMoveMouse)
- {
- /* Adjust center point if window was moved */
- gCenter = gLocalCenter;
- LocalToGlobal (&gCenter);
-
- gFirstTime = true;
- }
-
- return (! gMoveMouse);
- }
-
-
- #undef kShowMousePath
- #define kDegreesAdvance fixed1>>6
-
- #define FractToFix(a) ((Fixed)(a) >> 14)
-
- void MoveAutoMouse (void)
- {
- Fract cosine,
- sine;
-
- if (! gMoveMouse)
- return;
-
- /* Stop the automated mouse if user the moved mouse */
- if (gFirstTime)
- gFirstTime = false;
- else
- { if (RawMouseL != (*((long *) &gPosition)))
- {
- ToggleAutoMouse ();
- return;
- }
- }
-
- /* Advance the mouse to a new position */
- FractSineCosine (31 * gDegrees, &cosine);
- sine = FractSineCosine (29 * gDegrees, nil);
- gDegrees += kDegreesAdvance;
-
- gPosition.h = FixedToInt (FractToFix (cosine) * gScale) + gCenter.h;
- gPosition.v = FixedToInt (FractToFix (sine) * gScale) + gCenter.v;
- SetMousePosition (&gPosition);
-
- #ifdef kShowMousePath
- { Point curPosition;
- curPosition = gPosition;
- GlobalToLocal (&curPosition);
- MoveTo (curPosition.h, curPosition.v);
- Line (0, 0);
- }
- #endif
- }
-